package io.renren.sf.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.sf.dao.HzFixedInformationDicDao;
import io.renren.sf.entity.HzFixedInformationDicEntity;
import io.renren.sf.service.HzFixedInformationDicService;


@Service("hzFixedInformationDicService")
public class HzFixedInformationDicServiceImpl extends ServiceImpl<HzFixedInformationDicDao, HzFixedInformationDicEntity> implements HzFixedInformationDicService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<HzFixedInformationDicEntity> page = this.page(
                new Query<HzFixedInformationDicEntity>().getPage(params),
                new QueryWrapper<HzFixedInformationDicEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<HzFixedInformationDicEntity> queryYears(Integer curPage, Integer pageSize, String fixedInformationName) {
        curPage = (curPage-1) * pageSize;
        return this.baseMapper.queryYears(curPage, pageSize, fixedInformationName);
    }

    /**
     * 获取总记录数
     * @param fixedInformationName
     * @return
     */
    @Override
    public Integer queryFixedInformationDicsNum(String fixedInformationName) {
        return this.baseMapper.queryFixedInformationDicsNum(fixedInformationName);
    }

    /**
     * 根据yid、sid、cid分别查出年代、书体、书家顺序的字典信息list
     * @param yid
     * @param sid
     * @param cid
     * @return
     */
    @Override
    public List<HzFixedInformationDicEntity> findByIds(long yid, long sid, long cid) {
        return this.baseMapper.findByIds(yid, sid, cid);
    }

    @Override
    public List<HzFixedInformationDicEntity> queryByName(String informationName) {
        return this.baseMapper.selectList(
                new QueryWrapper<HzFixedInformationDicEntity>().eq("fixed_information_name", informationName)
                        .orderByAsc("iorder"));
    }

    @Override
    public List<HzFixedInformationDicEntity> queryByNameAndContent(String name, String content) {
        return this.baseMapper.selectList(new QueryWrapper<HzFixedInformationDicEntity>().eq("fixed_information_name", name).eq("fixed_information_content",content));
    }

    @Override
    public List<HzFixedInformationDicEntity> queryByNameAndRemarks(String name, String remarks) {
        return this.baseMapper.selectList(new QueryWrapper<HzFixedInformationDicEntity>().eq("fixed_information_name", name).eq("remarks",remarks));
    }

    @Override
    public Integer queryByNameAndRemarksNum(String fixedInformationName, String remarks) {
        return this.baseMapper.selectList(
                new QueryWrapper<HzFixedInformationDicEntity>().eq("fixed_information_name", fixedInformationName)
                        .eq("remarks", remarks)).size();
    }

    @Override
    public Long getIdByTypeAndName(String name, String type) {
        return this.baseMapper.getIdByTypeAndName(name, type);
    }

}